/*
 * VistaGrafico.java
 *
 * Created on 21 de noviembre de 2007, 11:16
 */

package algo3c3g7.mvc;

import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.Observable;
import java.util.Observer;

import algo3c3g7.funciones.Funcion;

/**
 *
 * @author  Athlon
 */
public class VistaGrafico extends javax.swing.JPanel implements Observer{
    
	/** Creates new form VistaGrafico */
    public VistaGrafico(ModeloIntervalos modelo) {
        initComponents();
        this.modeloIntervalo= modelo;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        grafico = new org.jdesktop.swingx.JXGraph();

        setLayout(new java.awt.BorderLayout());

        grafico.setMajorX(1.0);
        grafico.setMajorY(1.0);
        grafico.setView(new java.awt.geom.Rectangle2D.Double(-10.0, -10.0, 20.0, 20.0));

        javax.swing.GroupLayout jXGraph1Layout = new javax.swing.GroupLayout(grafico);
        grafico.setLayout(jXGraph1Layout);
        jXGraph1Layout.setHorizontalGroup(
            jXGraph1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 665, Short.MAX_VALUE)
        );
        jXGraph1Layout.setVerticalGroup(
            jXGraph1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 415, Short.MAX_VALUE)
        );

        add(grafico, java.awt.BorderLayout.CENTER);
    }// </editor-fold>
    
    
    // Variables declaration - do not modify
    private org.jdesktop.swingx.JXGraph grafico;
    private ModeloIntervalos modeloIntervalo;

    // End of variables declaration


	
	public void update(Observable o, Object arg) {
		Rectangle2D.Double bounds= new Rectangle2D.Double(
						   modeloIntervalo.getXMin(),
						   modeloIntervalo.getYMin(),
						   modeloIntervalo.getYMax(),
						   modeloIntervalo.getXMax()
		);
		
		/**
	    * minX: bounds.getX()
	    * minY: bounds.getY()
	    * maxY: bounds.getMaxX() (minX + bounds.getWidth())
	    * maxX: bounds.getMaxY() (minY + bounds.getHeight())
		*/
		
		grafico.setView(bounds);
		
	}
	
	public void graficarFuncion(Funcion funcion){
		
		try {
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DatosGraficoFuncion plot= new DatosGraficoFuncion(funcion);
		
		this.grafico.addPlots(Color.BLUE, plot);
		
		//this.grafico.repaint();
	}
    
}
